﻿#region Using Statements
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
#endregion

#region COPYRIGHT

/*
    Copyright (c) 2007, 2008, 2009, 2010, 2011
        Roland Rosenkranz (Glatzemann@email.de)
*/

#endregion

#region LICENSE

/*
    This file is part of starLiGHT.Input.

    starLiGHT.Input is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    starLiGHT.Input is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with starLiGHT.Input.  If not, see <http://www.gnu.org/licenses/>.

    
    ADDITIONAL (commercial) LICENSES for starLiGHT.Input are available on request.
*/

#endregion

#region Version Stuff
// **************[ starLiGHT.Engine SVN ]**********************
// * $Rev:: 3223                  $:  Revision of last commit *
// * $Author:: unknown            $:  Author of last commit   *
// * $Date:: 2011-01-11 15:47:16 #$:  Date of last commit     *
// ************************************************************
#endregion

namespace starLiGHT.Input
{
    public enum PhoneButtons
    {
        Back,
    }

#if WINDOWS_PHONE
    public class PhoneDevice : IControlDevice
    {
        GamePadState lastState;
        GamePadState actState;
        PlayerIndex playerIndex;

        ButtonControl buttonBack;

        private PhoneDevice()
        {
            buttonBack = new ButtonControl();
        }

        public PhoneDevice(PlayerIndex playerIndex)
            : this()
        {
            this.playerIndex = playerIndex;
        }

        /// <summary>
        /// Returns the actual connection status of the phone hardware buttons
        /// </summary>
        public Boolean IsConnected
        {
            get  { return true; }
        }

        /// <summary>
        /// Returns true if the InputManager recognized this GamePad as connected during an update since the start of your game
        /// </summary>
        public Boolean WasEverConnected
        {
            get { return true; }
        }

        public DeviceType DeviceType
        {
            get { return DeviceType.PHONE; }
        }

        public Boolean HasPlayerIndex
        {
            get { return true; }
        }

        public PlayerIndex PlayerIndex
        {
            get { return playerIndex; }
        }

        /// <summary>
        /// Is true if the gamepad was connected since the last update. This is valid only for
        /// one update cycle.
        /// </summary>
        public Boolean WasConnected
        {
            get { return true; }
        }

        /// <summary>
        /// Is true if the gamepad was disconnected since the last update. This is valid only for
        /// one update cycle.
        /// </summary>
        public Boolean WasDisconnected
        {
            get { return !actState.IsConnected && lastState.IsConnected; }
        }

        public void Update(GameTime gameTime)
        {
            lastState = actState;
            actState = GamePad.GetState(playerIndex, GamePadDeadZone.None);

            buttonBack.Update(actState.Buttons.Back);
        }

        public ButtonControl Button_Back
        {
            get { return buttonBack; }
        }
    }
#endif
}
